package com.caiyouxi.partner.service.impl;

import com.caiyouxi.common.bean.QueryParams;
import com.caiyouxi.common.bean.ResData;
import com.caiyouxi.common.cache.RedisService;
import com.caiyouxi.common.service.BaseService;
import com.caiyouxi.partner.mapper.PartnerMapper;
import com.caiyouxi.partner.model.PartnerBean;
import com.caiyouxi.partner.service.PartnerServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Transactional
public class PartnerServicesImpl extends BaseService implements PartnerServices{
    @Autowired
    private PartnerMapper mapper;
    @Autowired
    private RedisService redisService;

    @Override
    public ResData delete_partner(PartnerBean bean) {
        return success(mapper.delete_partner(bean.getId()));
    }

    @Override
    public ResData insert_selective(PartnerBean bean) {
        if(bean.getCreate_time() == null){
            bean.setCreate_time(new Date());
        }
        return success(mapper.insert_selective(bean));
    }

    @Override
    public ResData update_selective(PartnerBean bean) {
        if(bean.getUpdate_time() == null){
            bean.setUpdate_time(new Date());
        }
        return success(mapper.update_selective(bean));
    }

    @Override
    public ResData select_partner_list(PartnerBean bean) {
        Integer page_size = Integer.parseInt(redisService.get("sys.pagesize").toString());
        QueryParams pageList = new QueryParams();
        if(bean.getPage_size() == 0){
            bean.setPage_size(page_size);
        }
        pageList.setPage_size(bean.getPage_size());
        pageList.setPage(bean.getPage());
        pageList.setList(mapper.select_partner_list(bean));
        pageList.setTotal(mapper.select_partner_count(bean));
        return success(pageList);
    }
}
